﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Sun.Mvc.Models;
using Sun.Mvc.Framework;
using Sun.Mvc.BLL;
using Sun.Mvc.Models.ViewModels;
using System.Web.Http.Cors;

namespace Sun.Mvc.API.Controllers
{
    public class AccountController : ApiController
    {
        [EnableCors(origins: "http://localhost:2788", headers: "*", methods: "*")]
        [HttpPost]
        public JsonResult Login(Models.Users model)
        {
            JsonResult result = new JsonResult();

            BLL.Users usersBLL = new BLL.Users();
            string Salt = usersBLL.GetSaltByAccount(model.UserName);
            if (!string.IsNullOrEmpty(Salt))
            {
                model.PassWord = Framework.Salt.HashSalt(model.PassWord, Salt);
                Models.Users usersModel = usersBLL.GetUserInfoByAccount(model);
                if (usersModel != null)
                {
                    //创建票据

                    result.Code = 200;
                    result.Message = "登录成功";
                }
            }

            return result;
        }

        [HttpGet]
        public string Test()
        {
            return "123";
        }
    }
}
